package com.cskaoyan.typehandler;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author gatsby
 * @since 2022/10/12 15:15
 */
@MappedTypes(Boolean.class)
@MappedJdbcTypes(JdbcType.TINYINT)
public class BooleanTypeHandler implements TypeHandler<Boolean> {
    ObjectMapper objectMapper = new ObjectMapper();
    @Override
    public void setParameter(PreparedStatement preparedStatement, int i, Boolean aBoolean, JdbcType jdbcType) throws SQLException {
        //String value = objectMapper.writeValueAsString(aBoolean);//也可以用Gson
        //preparedStatement.setString(i,value);
    }

    @Override
    public Boolean getResult(ResultSet resultSet, String s) throws SQLException {
        return null;
    }

    @Override
    public Boolean getResult(ResultSet resultSet, int i) throws SQLException {
        return null;
    }

    @Override
    public Boolean getResult(CallableStatement callableStatement, int i) throws SQLException {
        return null;
    }
}
